package Binrary_Management_System.ioPeration;

import Binrary_Management_System.Book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 何华树
 * Date: 2024-09-13
 * Time: 14:05
 */
public class BorrowOperation implements IOperation{

    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书！");

        int currentSize = bookList.getUseSize();

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要借阅的书的书名：");
        String name = scanner.nextLine();
        for (int i = 0; i < currentSize; i++) {
            if(bookList.getBook(i).getName().equals(name)) {
                if(!bookList.getBook(i).isBorrowed()) {
                    bookList.getBook(i).setBorrowed(true);
                    System.out.println("借阅成功！");
                    return;
                }else {
                    System.out.println("这本书已经被借出了，无法借阅！");
                    return;
                }
            }
        }
        System.out.println("没有你要借阅的图书！");
    }
}
